package com.ymatou.iapi.refund.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.optrade.resp.TradingServiceResp;
import com.ymatou.iapi.refund.parameter.AddNewMessageBean;
import com.ymatou.iapi.refund.parameter.CreateReturnBillBean;
import com.ymatou.iapi.refund.service.AddNewMessageCall;
import com.ymatou.iapi.refund.service.CreateReturnBillCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.RefundCallService;
import com.ymttest.business.service.YMTTrading.TradingCallService;
import com.ymttest.business.service.YMTTrading.TradingPlaceOrderCallService;
import com.ymttest.database.model.CS_ReturnApplyExtPictures;
import com.ymttest.database.model.CS_ReturnApplyMessage;
import com.ymttest.database.sqlwapper.CS_ReturnApplyExtPicturesWapper;
import com.ymttest.database.sqlwapper.CS_ReturnApplyMessageWapper;
import com.ymttest.utils.EnvSetup;
/**
*添加留言
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_AddNewMessage{
	private static AddNewMessageBean bean;
	private static AddNewMessageCall call;
	private static CreateReturnBillBean createBean=new CreateReturnBillBean();;
	private static CreateReturnBillCall createCall=new CreateReturnBillCall();
	private static CS_ReturnApplyExtPicturesWapper picwapper=new CS_ReturnApplyExtPicturesWapper();
	private static CS_ReturnApplyMessageWapper messageWapper=new CS_ReturnApplyMessageWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("添加留言");
	}

	@Before
	public void caseUp() {
		bean=new AddNewMessageBean();
		call=new AddNewMessageCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddNewMessage_001() {
		Logger.start(true,"正例-添加留言-图片长度为1");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService=new TradingPlaceOrderCallService();
			RefundCallService service=new RefundCallService();
			TradingServiceResp tradingServiceResp=tradingService.placeOrderWithTwoProcutInOneOrder(false, false);
			
			createBean=service.setCreateReturnBillBean_AcceptOrder(tradingServiceResp,tradingService,false);
			
			createCall=service.callCreateReturnBill(createBean,createCall);
			
			bean.setReturnBillId(createCall.getCallData().getReturnBillList().get(0).getReturnId());
			bean.setContent("自动化测试");
			bean.setUserId(createBean.getUserid());
			List<String> PicUrls=new ArrayList();
			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o.png");
			bean.setPicUrls(PicUrls);
			
			call.setData(bean);
			call.callService();			
			verifyReturn();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddNewMessage_002() {
		Logger.start(true,"正例-添加留言-图片长度为2");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService=new TradingPlaceOrderCallService();
			RefundCallService service=new RefundCallService();
			TradingServiceResp tradingServiceResp=tradingService.placeOrderWithTwoProcutInOneOrder(false, false);
			createBean=service.setCreateReturnBillBean_AcceptOrder(tradingServiceResp,tradingService,false);
			createCall=service.callCreateReturnBill(createBean,createCall);
			
			bean.setReturnBillId(createCall.getCallData().getReturnBillList().get(0).getReturnId());
			bean.setContent("自动化测试");
			bean.setUserId(createBean.getUserid());
			List<String> PicUrls=new ArrayList();
			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o.png");
			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o1.png");
			bean.setPicUrls(PicUrls);
			
			call.setData(bean);
			call.callService();			
			verifyReturn();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddNewMessage_003() {
		Logger.start(true,"正例-添加留言-不接单，走取消流程完成");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService=new TradingPlaceOrderCallService();
			RefundCallService service=new RefundCallService();
			TradingServiceResp tradingServiceResp=tradingService.placeOrderWithTwoProcutInOneOrder(false, false);
			createBean=service.setCreateReturnBillBean(tradingServiceResp,tradingService);
			createCall=service.callCreateReturnBill(createBean,createCall);
			
			bean.setReturnBillId(createCall.getCallData().getReturnBillList().get(0).getReturnId());
			bean.setContent("自动化测试");
			bean.setUserId(createBean.getUserid());
			List<String> PicUrls=new ArrayList();
			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o.png");
			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o1.png");
			bean.setPicUrls(PicUrls);
			
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals(true,call.getMsg1().contains("当前状态(退货退款完成)不允许留言"), "验证Msg");
			Logger.verifyEquals("201",call.getStatus(), "验证Status");
			Logger.verifyEquals("1",call.getbCode(), "验证bCode");
			Logger.verifyEquals("0",call.getRetData(), "验证RetData");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddNewMessage_004() {
		Logger.start(true,"正例-添加留言-ReturnBillId 为空");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService=new TradingPlaceOrderCallService();
			RefundCallService service=new RefundCallService();
			TradingServiceResp tradingServiceResp=tradingService.placeOrderWithTwoProcutInOneOrder(false, false);
			createBean=service.setCreateReturnBillBean_AcceptOrder(tradingServiceResp,tradingService,false);
			createCall=service.callCreateReturnBill(createBean,createCall);
			
			bean.setReturnBillId("");
			bean.setContent("自动化测试");
			bean.setUserId(createBean.getUserid());
			List<String> PicUrls=new ArrayList();
			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o.png");
			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o1.png");
			bean.setPicUrls(PicUrls);
			
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals(true,call.getMsg1().contains("退款Id不能为空"), "验证Msg");
			Logger.verifyEquals("400",call.getStatus(), "验证Status");
			Logger.verifyEquals("12",call.getbCode(), "验证bCode");
			Logger.verifyEquals("0",call.getRetData(), "验证RetData");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddNewMessage_004_1() {
		Logger.start(true,"正例-添加留言-ReturnBillId不存在");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService=new TradingPlaceOrderCallService();
			RefundCallService service=new RefundCallService();
			TradingServiceResp tradingServiceResp=tradingService.placeOrderWithTwoProcutInOneOrder(false, false);
			createBean=service.setCreateReturnBillBean_AcceptOrder(tradingServiceResp,tradingService,false);
			createCall=service.callCreateReturnBill(createBean,createCall);
			
			bean.setReturnBillId("99999");
			bean.setContent("自动化测试");
			bean.setUserId(createBean.getUserid());
			List<String> PicUrls=new ArrayList();
			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o.png");
			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o1.png");
			bean.setPicUrls(PicUrls);
			
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals(true,call.getMsg1().contains("没有对应的退款单据"), "验证Msg");
			Logger.verifyEquals("201",call.getStatus(), "验证Status");
			Logger.verifyEquals("1",call.getbCode(), "验证bCode");
			Logger.verifyEquals("0",call.getRetData(), "验证RetData");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddNewMessage_005() {
		Logger.start(true,"正例-添加留言-PicUrls 为空");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService=new TradingPlaceOrderCallService();
			RefundCallService service=new RefundCallService();
			TradingServiceResp tradingServiceResp=tradingService.placeOrderWithTwoProcutInOneOrder(false, false);
			createBean=service.setCreateReturnBillBean_AcceptOrder(tradingServiceResp,tradingService,false);
			createCall=service.callCreateReturnBill(createBean,createCall);
			
			bean.setReturnBillId(createCall.getCallData().getReturnBillList().get(0).getReturnId());
			bean.setContent("自动化测试");
			bean.setUserId(createBean.getUserid());
			List<String> PicUrls=new ArrayList();
//			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o.png");
//			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o1.png");
			bean.setPicUrls(PicUrls);
			
			call.setData(bean);
			call.callService();			
			verifyReturn();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddNewMessage_006() {
		Logger.start(true,"正例-添加留言-Content 为空");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService=new TradingPlaceOrderCallService();
			RefundCallService service=new RefundCallService();
			TradingServiceResp tradingServiceResp=tradingService.placeOrderWithTwoProcutInOneOrder(false, false);
			createBean=service.setCreateReturnBillBean_AcceptOrder(tradingServiceResp,tradingService,false);
			createCall=service.callCreateReturnBill(createBean,createCall);
			
			bean.setReturnBillId(createCall.getCallData().getReturnBillList().get(0).getReturnId());
			bean.setContent("");
			bean.setUserId(createBean.getUserid());
			List<String> PicUrls=new ArrayList();
			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o.png");
			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o1.png");
			bean.setPicUrls(PicUrls);
			
			call.setData(bean);
			call.callService();			
			verifyReturn();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddNewMessage_007() {
		Logger.start(true,"正例-添加留言-Userid 为空");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService=new TradingPlaceOrderCallService();
			RefundCallService service=new RefundCallService();
			TradingServiceResp tradingServiceResp=tradingService.placeOrderWithTwoProcutInOneOrder(false, false);
			createBean=service.setCreateReturnBillBean_AcceptOrder(tradingServiceResp,tradingService,false);
			createCall=service.callCreateReturnBill(createBean,createCall);
			
			bean.setReturnBillId(createCall.getCallData().getReturnBillList().get(0).getReturnId());
			bean.setContent("自动化测试");
			bean.setUserId(0);
			List<String> PicUrls=new ArrayList();
			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o.png");
			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o1.png");
			bean.setPicUrls(PicUrls);
			
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals(true,call.getMsg1().contains("请传入用户Id"), "验证Msg");
			Logger.verifyEquals("400",call.getStatus(), "验证Status");
			Logger.verifyEquals("12",call.getbCode(), "验证bCode");
			Logger.verifyEquals("0",call.getRetData(), "验证RetData");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddNewMessage_008() {
		Logger.start(true,"正例-添加留言-Userid 不存在");
		try {
			//创建一个订单
			TradingPlaceOrderCallService tradingService=new TradingPlaceOrderCallService();
			RefundCallService service=new RefundCallService();
			TradingServiceResp tradingServiceResp=tradingService.placeOrderWithTwoProcutInOneOrder(false, false);
			createBean=service.setCreateReturnBillBean_AcceptOrder(tradingServiceResp,tradingService,false);
			createCall=service.callCreateReturnBill(createBean,createCall);
			
			bean.setReturnBillId(createCall.getCallData().getReturnBillList().get(0).getReturnId());
			bean.setContent("自动化测试");
			bean.setUserId(99999);
			List<String> PicUrls=new ArrayList();
			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o.png");
			PicUrls.add("http://pic1.ymatou.com/G01/M00/3D/8C/rBBlD1siHfKAZ6HMAAUW7sFyhsM617_320_187_o1.png");
			bean.setPicUrls(PicUrls);
			
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals(true,call.getMsg1().contains("买家账号与单据当前买家账号不一致"), "验证Msg");
			Logger.verifyEquals("201",call.getStatus(), "验证Status");
			Logger.verifyEquals("1",call.getbCode(), "验证bCode");
			Logger.verifyEquals("0",call.getRetData(), "验证RetData");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private void verifyReturn()
	{
		CS_ReturnApplyMessage message=messageWapper.selectByApplyBillId(bean.getReturnBillId()).get(0);
		List<CS_ReturnApplyExtPictures> pics=picwapper.selectByRefId(message.getId());
		
		Logger.verifyEquals("",call.getMsg1(), "验证Msg");
		Logger.verifyEquals("200",call.getStatus(), "验证Status");
		Logger.verifyEquals("0",call.getbCode(), "验证bCode");
		Logger.verifyEquals("0",call.getRetData(), "验证RetData");
		
		Logger.verifyEquals(message.getReturnApplyBillId(),bean.getReturnBillId(), "验证数据库CS_ReturnApplyMessage表ReturnBillId 是否一致");
		Logger.verifyEquals(message.getOperatorId(),bean.getUserId(), "验证数据库CS_ReturnApplyMessage表OperatorId 是否一致");
		Logger.verifyEquals(message.getOperatorName(),EnvSetup.getData("BuyUserName"), "验证数据库CS_ReturnApplyMessage表OperatorName 是否一致");
		Logger.verifyEquals(2,message.getOperatorType(), "验证数据库CS_ReturnApplyMessage表OperatorType 是否一致");
		Logger.verifyEquals(message.getContent(),bean.getContent(), "验证数据库CS_ReturnApplyMessage表Content 是否一致");
		Logger.verifyEquals(false,message.getIsDel(), "验证数据库CS_ReturnApplyMessage表IsDel 是否一致");
	
		Logger.verifyEquals(bean.getPicUrls().size(),pics.size(), "验证返回的数据与数据库数量一致");
		for(int i=0;i<pics.size();i++)
		{
			Logger.verifyEquals(message.getId(),pics.get(i).getRefId(), "验证数据库CS_ReturnApplyExtPictures第"+(i+1)+"个与数据库数量一致");
			Logger.verifyEquals(pics.get(i).getImgUrl(),bean.getPicUrls().get(i), "验证数据库CS_ReturnApplyExtPictures第"+(i+1)+"个与数据库数量一致");
		}
	}
}